Add keys method for Php::Value#115
Open
andot wants to merge 2 commits intoCopernicaMarketingSoftware:masterfrom
andot:keys
Open
Add keys method for Php::Value#115andot wants to merge 2 commits intoCopernicaMarketingSoftware:masterfrom andot:keys
andot wants to merge 2 commits intoCopernicaMarketingSoftware:masterfrom
andot:keys
Conversation
This method can get the array keys, or object property names, include private & protected properties. It is similar to working in PHP: array_keys($array); and array_keys((array)$object); but the return value type is std::vector<Php::Value>, and it's faster than using php function.
Contributor
|
I think this feature is partly duplicates code of valueiterator: .../include/valueiterator.h .../zend/hashiterator.h. std::vector<Php::Value> keys;
keys.reserve(array.size());
for(auto &it: array)
{
keys.push_back(it.first);
} |
Contributor
Author
|
The HashIterator has a bug, if the array has a reference item, for(auto &it: array) will break the array. for example: Php::Value getKeys(Php::Parameters ¶ms) {
Php::Value array = params[0];
std::vector<Php::Value> keys;
keys.reserve(array.size());
for(auto &it: array)
{
keys.push_back(it.first);
}
}<?php
$a = array();
$a[] = &$a;
$a[] = "hello";
var_dump($a);
var_dump(getKeys($a));
var_dump($a);
?>the result is: |
Contributor
Author
|
and when use iterator on an object Value, we can only get the public properties. But the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This method can get the array keys, or object property names, include private & protected properties.
It is similar to working in PHP:
and
but the return value type is std::vectorPhp::Value, and it's faster than using php function.